import JSEncrypt from 'jsencrypt'

const publicKey = `MIGfMA0GCSqGSIb3DQEBAQUAA4GNADCBiQKBgQDAx2pKyhrOicoi7tptgQhMIS3JXe3Zk8vc/IJVn+y8XSMgiYquUItLIGUsgWWT9I1IBrDogChPNkYHJSKcfhTLy8kT3lCLtjuxnhsCfiL4lUFzxpY3p4JkYMu5jq+J/kpG2Y9HlwOFqpJEA7V1ABWYXpeeZVWU4DiLlmn3oUzNpwIDAQAB`

const encodeString = (str) => {
  const encrypt  = new JSEncrypt()
  encrypt.setPublicKey(publicKey)
  return encrypt.encrypt(str).toString()
}

const decodeString = (str) => {
  const encrypt  = new JSEncrypt()
  encrypt.setPublicKey(publicKey)
  return encrypt.decrypt(str).toString()
}

export const RsaEncrypto = {
  encodeString,
  decodeString
}
